/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-04-24
 * Time: 8:58
 */
class Max <T extends Comparable<T> > { //此处限制了 泛型被擦除的上界,使该泛型只能接收Comparable的子类
    public T maxArrays( T[]arr ) {
        T max = arr[0];
        for (int i = 0; i < arr.length; i++) {
            //此处是引用类型的比较,要使用comparaTo方法
            if( max.compareTo(arr[i]) < 0 ) {
                max = arr[i];
            }
        }
        return max;
    }
}
public class Demo01 {
    //实现一个泛型类,包含一个方法,返回数组的最大值
        public static void main(String[] args) {
            Max<String> max = new Max<>();
            String []array = {"a","b","c","d","zss"};
            String ret = max.maxArrays(array);
            System.out.println(ret);
        }

}
